/**
 * 进件管理等待放款批准放款
 */
import './index.less'
import tem from './index.html'
import $_fn from '~plugins'
class approveCtrl {
  constructor($scope,$rootScope,http,$ui) {
      $scope.cancel = function () {
          $rootScope.$uiDirectiveModal.close() //关闭方法
      }
      console.log('订单id'+$scope.id)
      //订单信息请求
      $scope.guanLiZu=function(datas){
      	  http.post('loanMoneyInit.do',datas,function (data) {
				if(data.errcode==1){
					$scope.approveData=data.data
					$scope.$apply()
				}else{
					$ui.toast({
						text:data.errmsg,
						type:'warning',
						appendTo:'.approve'
					})
				}
	        },function(_data){
	            console.log(_data);//报错
	      })
      }
  	  $scope.guanLiZu({oid:$scope.id});
  	//输入错误提示
  	$scope.err=function(datas){
  		$scope[datas]=true;
  		setTimeout(function() {
  			$scope[datas]=false;
  			$scope.$apply()
  		}, 1000);
  	}
  	
  	//初始化对象
  	$scope.param1={
  		oid:$scope.id
  	}
  	//添加管理员提交
  	  $scope.tiJiao1=function(){
  	  		console.log('添加管理员')
	  	  	if(!$scope.param1.credit_time){
	  	  		$ui.toast({
					text:'请选择放款日期',
					type:'warning',
					appendTo:'.approve'
				})
	  	  		$scope.err('credit_time')
	  	  		return 
	  	  	}
	  	  	if(!$scope.param1.credit_remark || $scope.param1.credit_remark==''){
	  	  		$ui.toast({
					text:'请填写放款备注',
					type:'warning',
					appendTo:'.approve'
				})
	  	  		return 
	  	  	}
  	  		http.post('loanMoney.do',$scope.param1,function (data) {
				if(data.errcode==1){
					/*$ui.toast({
						text:data.errmsg,
						type:'succeed',
						appendTo:'#addAdmin'
					})*/
					$scope.cancel()//关闭弹窗
					window.history.go(0)
				}else{
					$ui.toast({
						text:data.errmsg,
						type:'warning',
						appendTo:'.approve'
					})
				}
	        },function(_data){
	            console.log(_data);//报错
	      	})
  	  }
  }
}
approveCtrl.$inject = ['$scope','$rootScope','http','$ui']
module.exports = angular.module('directive.approve', []).directive('approve', function() {
    return {
        template: tem,
        replace:true,
        controller: approveCtrl,
        scope:{
        	id:'@'
        }
    }
}).name